import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/config/router_config.dart';
import 'package:s_mankey/model/favorites_model.dart';
import 'package:s_mankey/provider/provider_widget.dart';
import 'package:s_mankey/ui/widget/home_car_widget.dart';
import 'package:s_mankey/view_model/favoriters_list_vmodel.dart';

import 'audio_list.dart';

class AudioFavorites extends StatefulWidget {
  AudioFavorites({Key key}) : super(key: key);

  @override
  _AudioFavoritesState createState() {
    return _AudioFavoritesState();
  }
}

class _AudioFavoritesState extends State<AudioFavorites>
    with SingleTickerProviderStateMixin {

  var list = [
    '点赞',
    '收藏',
  ];

  int tabIndex = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ProviderWidget<FavoritesListVModel>(
      model: FavoritesListVModel(),
      onModelReady: (model) => model.initData(),
      builder: (context, model, child) {
        return (model.datas == null)
            ? Text('')
            : DefaultTabController(
                length: list.length,
                initialIndex: 0,
                child: Builder(builder: (context) {
                  return Scaffold(
                      backgroundColor: AppColor.ScaffoldBackgoundColor,
                      appBar: AppBar(
                        elevation: AppCustomSize.AppBarElevation,
                        title: TabBar(
                            indicatorColor: Color(
                              0xffff3f7f,
                            ),
                            indicatorPadding: EdgeInsets.only(left: 20.0),
                            indicatorSize: TabBarIndicatorSize.tab,
                            indicatorWeight: 2,
                            labelPadding: EdgeInsets.only(left: 20),
                            labelStyle: TextStyle(
                                fontSize: AppFontSize.Size16,
                                color: Colors.black),
                            unselectedLabelStyle: TextStyle(
                                fontSize: AppFontSize.Size14,
                                color: Color(0xffbababa)),
                            isScrollable: true,
                            onTap: (index) {},
                            tabs: List.generate(
                                list.length,
                                (index) => Tab(
                                      text: list[index],
                                    ))),
                      ),
                      body: TabBarView(
                          children: List.generate(
                              list.length,
                              (index) =>
                                  FavoritesWidget(datas: model.datas[index]))));
                }));
      },
    );
  }
}

class FavoritesWidget extends StatelessWidget {
  final datas;

  FavoritesWidget({this.datas});

  @override
  Widget build(BuildContext context) {
    List<LikeData> _datas = datas;
    return ListView.builder(
      physics: NeverScrollableScrollPhysics(),
      itemCount: _datas.length,
      itemBuilder: (BuildContext context, int index) {
        return GestureDetector(
            onTap: () {
              Navigator.pushNamed(context, RouterName.audioDetail,
                  arguments: {'vid': _datas[index].id});
            },
            child: Container(
              decoration: BoxDecoration(
                  border:
                      Border(bottom: BorderSide(color: AppColor.dividerColor))),
              margin: EdgeInsets.fromLTRB(15, 0, 15, 0),
              padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
              child: Row(
                children: [
                  ClipOval(
                    clipBehavior: Clip.antiAlias,
                    child: Image.network(
                      _datas[index].headImg,
                      width: 40,
                      height: 40,
                      fit: BoxFit.cover,
                    ),
                  ),
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
                      child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                child: Text(
                                  _datas[index].courseTitle,
                                  style: TextStyle(
                                      color: Colors.black,
                                      fontSize: AppFontSize.Size16),
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ),
                              Text(
                                _datas[index].language,
                                style: TextStyle(color: Color(0xff747474)),
                              ),
                              IconFonts.rightIcon,
                              Text(
                                _datas[index].time,
                                style: TextStyle(
                                    color: Color(0xff747474),
                                    fontSize: AppFontSize.Size14),
                              ),
                            ],
                          ),
                          Padding(
                            padding: const EdgeInsets.only(top: 2),
                            child: Text(
                              _datas[index].profile,
                              style: TextStyle(
                                  color: Color(0xff747474),
                                  fontSize: AppFontSize.Size14),
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  Icon(Icons.play_circle_filled),
                ],
              ),
            ));
      },
    );
  }
}
